package com.csx.saas.platform.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.csx.basic.base.service.SuperCacheServiceImpl;
import com.csx.basic.cache.model.CacheKeyBuilder;
import com.csx.saas.common.cache.system.SystemMenuCacheKeyBuilder;
import com.csx.saas.platform.system.dao.SystemMenuMapper;
import com.csx.saas.platform.system.entity.SystemMenu;
import com.csx.saas.platform.system.service.SystemMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 业务实现类
 * 菜单
 * </p>
 *
 * @author ChenSongXin
 * @date 2021-02-28
 */
@Slf4j
@Service
@DS("#thread.tenant")
public class SystemMenuServiceImpl extends SuperCacheServiceImpl<SystemMenuMapper, SystemMenu> implements SystemMenuService {

    @Override
    protected CacheKeyBuilder cacheKeyBuilder() {
        return new SystemMenuCacheKeyBuilder();
    }

    protected SystemMenuService currentProxy() {
        return ((SystemMenuService) AopContext.currentProxy());
    }

    @Override
    public List<SystemMenu> findVisibleMenu(Long userId) {
        return baseMapper.findVisibleMenu(userId);
    }

    @Override
    public SystemMenu getByIdCache(Serializable id) {
        SystemMenu systemMenu = super.getByIdCache(id);
        if(systemMenu.getParentId()!=0){
            SystemMenu parentSystemMenu = super.getByIdCache(systemMenu.getParentId());
            systemMenu.setParentName(parentSystemMenu.getLabel());
        }

        return systemMenu;
    }
}
